#ifndef WIFI_CONFIG_H
#define WIFI_CONFIG_H

#include <WiFi.h>
#include <WebServer.h>

// 前置声明舵机控制回调函数类型
typedef void (*AngleEventCallback)(int angle);

class WiFiConfig
{
public:
    void connectToWiFi(char *ssid = nullptr, char *password = nullptr);
    void startConfigPortal();
    void handleClient();
    // 设置舵机控制回调函数
    void setAngleCallback(AngleEventCallback callback) {
        angleCallback = callback;
    }

private:
    const char *apSSID = "TouAP";
    const char *apPassword = "12345678";
    WebServer server = WebServer(80);
    bool configured = false;
    AngleEventCallback angleCallback = nullptr; // 舵机控制回调函数
    
    // 私有函数声明
    static void _wifiMonitor(void* pvParameters);
    void _handleAPRoot();
    void _handleAPSave();
    void _advertiseIP(IPAddress ip);
    void _handleGPIO2();
    void _handleControlGPIO2();
};

#endif